home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / J A V A / Java Development Kit V1.2 / jdk12-win32(1).exe / data1.cab / demos / demo / jfc / SwingSet / SwingSet.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  74.8 KB  |  1,997 lines

  1. /*
  2.  * @(#)SwingSet.java    1.74 98/06/09
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. import javax.swing.*;
  16. import javax.swing.event.*;
  17. import javax.swing.text.*;
  18. import javax.swing.border.*;
  19. import javax.swing.colorchooser.*;
  20. import javax.swing.filechooser.*;
  21. import javax.accessibility.*;
  22.  
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import java.beans.*;
  26. import java.util.*;
  27. import java.io.*;
  28. import java.applet.*;
  29. import java.net.*;
  30.  
  31. /**
  32.  * A demo that shows all of the Swing components.
  33.  *
  34.  * @version 1.74 06/09/98
  35.  * @author Jeff Dinkins (code, code, and more code)
  36.  * @author Chester Rose (graphic artist)
  37.  * @author Arnaud Weber (applet support)
  38.  * @author Peter Korn   (accessbility support)
  39.  * @author Georges Saab (menus, toolbars)
  40.  */
  41. public class SwingSet extends JPanel
  42. {
  43.     // This
  44.     SwingSet swing;
  45.  
  46.     // The Frame
  47.     public static JFrame frame;
  48.  
  49.     // Current ui
  50.     public String currentUI = "Metal";
  51.  
  52.     // The width and height of the frame
  53.     public static int WIDTH = 790;
  54.     public static int HEIGHT = 550;
  55.     public static int INITIAL_WIDTH = 400;
  56.     public static int INITIAL_HEIGHT = 200;
  57.  
  58.     public final static Dimension hpad5 = new Dimension(5,1);
  59.     public final static Dimension hpad10 = new Dimension(10,1);
  60.     public final static Dimension hpad20 = new Dimension(20,1);
  61.     public final static Dimension hpad25 = new Dimension(25,1);
  62.     public final static Dimension hpad30 = new Dimension(30,1);
  63.     public final static Dimension hpad40 = new Dimension(40,1);
  64.     public final static Dimension hpad80 = new Dimension(80,1);
  65.  
  66.     public final static Dimension vpad5 = new Dimension(1,5);
  67.     public final static Dimension vpad10 = new Dimension(1,10);
  68.     public final static Dimension vpad20 = new Dimension(1,20);
  69.     public final static Dimension vpad25 = new Dimension(1,25);
  70.     public final static Dimension vpad30 = new Dimension(1,30);
  71.     public final static Dimension vpad40 = new Dimension(1,40);
  72.     public final static Dimension vpad80 = new Dimension(1,80);
  73.  
  74.     public final static Insets insets0 = new Insets(0,0,0,0);
  75.     public final static Insets insets5 = new Insets(5,5,5,5);
  76.     public final static Insets insets10 = new Insets(10,10,10,10);
  77.     public final static Insets insets15 = new Insets(15,15,15,15);
  78.     public final static Insets insets20 = new Insets(20,20,20,20);
  79.  
  80.     public final static Border emptyBorder0 = new EmptyBorder(0,0,0,0);
  81.     public final static Border emptyBorder5 = new EmptyBorder(5,5,5,5);
  82.     public final static Border emptyBorder10 = new EmptyBorder(10,10,10,10);
  83.     public final static Border emptyBorder15 = new EmptyBorder(15,15,15,15);
  84.     public final static Border emptyBorder20 = new EmptyBorder(20,20,20,20);
  85.  
  86.     public final static Border etchedBorder10 = new CompoundBorder(
  87.                                                         new EtchedBorder(),
  88.                                                         emptyBorder10);
  89.  
  90.     public final static Border raisedBorder = new BevelBorder(BevelBorder.RAISED);
  91.     public final static Border lightLoweredBorder = new BevelBorder(BevelBorder.LOWERED, 
  92.                                                           Color.white, Color.gray);
  93.     public final static Border loweredBorder = new SoftBevelBorder(BevelBorder.LOWERED);
  94.  
  95.     public Font defaultFont = new Font("Dialog", Font.PLAIN, 12);
  96.     public Font boldFont = new Font("Dialog", Font.BOLD, 12);
  97.     public Font bigFont = new Font("Dialog", Font.PLAIN, 18);
  98.     public Font bigBoldFont = new Font("Dialog", Font.BOLD, 18);
  99.     public Font reallyBigFont = new Font("Dialog", Font.PLAIN, 18);
  100.     public Font reallyBigBoldFont = new Font("Dialog", Font.BOLD, 24);
  101.  
  102.     // L&F radio buttons
  103.     JRadioButtonMenuItem macMenuItem;
  104.     JRadioButtonMenuItem metalMenuItem;
  105.     JRadioButtonMenuItem motifMenuItem;
  106.     JRadioButtonMenuItem windowsMenuItem;
  107.  
  108.     // Some images used in the demo
  109.     public ImageIcon jpgIcon;
  110.     public ImageIcon gifIcon;
  111.  
  112.     public ImageIcon blueDot;
  113.     public ImageIcon redDot;
  114.     public ImageIcon invisibleDot;
  115.  
  116.     public ImageIcon duke2;
  117.     public ImageIcon dukeSnooze;
  118.     public ImageIcon dukeWave;
  119.     public ImageIcon dukeWaveRed;
  120.     public ImageIcon dukeMagnify;
  121.  
  122.     public ImageIcon cow;
  123.  
  124.     public ImageIcon tiger;
  125.     public ImageIcon littleTiger;
  126.  
  127.     public ImageIcon upButton;
  128.     public ImageIcon downButton;
  129.     public ImageIcon disabledButton;
  130.  
  131.  
  132.     // The panels used in the demo
  133.     public JPanel borderPanel;
  134.     public JPanel borderedPanePanel;
  135.     public JPanel buttonPanel;
  136.     public JPanel checkboxPanel;
  137.     public JPanel comboBoxPanel;
  138.     public JPanel dateChooserPanel;
  139.     public JPanel debugGraphicsPanel;
  140.     public JPanel htmlPanel;
  141.     public JPanel labelPanel;
  142.     public JPanel listBoxPanel;
  143.     public JPanel logoPanel;
  144.     public JPanel menuPanel;
  145.     public JPanel progressBarPanel;
  146.     public JPanel radioButtonPanel;
  147.     public JPanel scrollPanePanel;
  148.     public JPanel sliderPanel;
  149.     public JPanel splitPanePanel;
  150.     public JPanel tablePanel;
  151.     public JPanel textPanel;
  152.     public JPanel toggleButtonPanel;
  153.     public JPanel toolTipPanel;
  154.     public JPanel treePanel;
  155.     public JPanel windowPanel;
  156.  
  157.     // Track progress
  158.     public static int totalPanels = 23; // PENDING(jeff) there has got to be a better way...
  159.     public static int currentProgressValue;
  160.     public static JLabel progressLabel = null;
  161.     public static JProgressBar progressBar = null;
  162.  
  163.     // Used when switching to DebugGraphicsPanel
  164.     public Component previousPage;
  165.  
  166.     // Button controls
  167.     public Vector currentControls;
  168.     public Vector labels = new Vector();
  169.     public Vector buttons = new Vector();
  170.     public Vector checkboxes = new Vector();
  171.     public Vector radioButtons = new Vector();
  172.     public Vector toggleButtons = new Vector();
  173.  
  174.     // Some components used in the demo
  175.     public JTabbedPane tabbedPane;
  176.     public JPanel borderedPane;
  177.     public JList listBox;
  178.     public TabPlacementChanger tabPlacement;
  179.     public int toolTipIndex;
  180.  
  181.     // This != null if we are an applet
  182.     java.applet.Applet applet;
  183.     static SwingSet instance;
  184.  
  185.     public SwingSet() {
  186.     this(null);
  187.     }
  188.  
  189.     /*******************************************/
  190.     /****** Construct the SwingSet demo ********/
  191.     /*******************************************/
  192.     public SwingSet(java.applet.Applet anApplet) {
  193.     super(true); // double buffer
  194.  
  195.     instance = this;
  196.     applet = anApplet;
  197.     loadImages();
  198.     swing = this;
  199.     setName("Main SwingSet Panel");
  200.     DebugGraphics.setFlashTime(30);
  201.     setFont(defaultFont);
  202.     setLayout(new BorderLayout());
  203.         currentProgressValue = 0;
  204.  
  205.     // Add a MenuBar
  206.     add(createMenuBar(), BorderLayout.NORTH);
  207.  
  208.     // Create a tab pane
  209.     tabbedPane = new JTabbedPane();
  210.  
  211.         // Add magic key to enable timer logging
  212.     // PENDING(Arnaud) - is this really needed? 
  213.         tabbedPane.registerKeyboardAction(new ToggleLogging(),
  214.              KeyStroke.getKeyStroke('l', InputEvent.ALT_MASK), WHEN_IN_FOCUSED_WINDOW);
  215.         
  216.     // Add the tab to the center
  217.     add(tabbedPane, BorderLayout.CENTER);
  218.  
  219.     // Add the Button panel
  220.     progressLabel.setText("Loading Title Page");
  221.     ImageIcon swingLogo = loadImageIcon("images/swingLabelSmall.gif","Swing!");
  222.     JPanel logoPanel = createLogo();
  223.     tabbedPane.addTab("", swingLogo, logoPanel);
  224.     // set the Tab's AccessibleName 'cause we are using a graphic only
  225.     tabbedPane.getAccessibleContext().getAccessibleChild(tabbedPane.indexOfTab(swingLogo)).getAccessibleContext().setAccessibleName("Swing!");
  226.  
  227.     tabbedPane.setSelectedIndex(0);
  228.     progressBar.setValue(++currentProgressValue);
  229.  
  230.     // Buttons
  231.     progressLabel.setText("Loading Button Example");
  232.     buttonPanel = new ButtonPanel(this);
  233.     tabbedPane.addTab("Buttons", null, buttonPanel);
  234.     progressBar.setValue(++currentProgressValue);
  235.  
  236.     // RadioButtons
  237.     progressLabel.setText("Loading RadioButton Example");
  238.     radioButtonPanel = new RadioButtonPanel(this);
  239.     tabbedPane.addTab("RadioButtons", null, radioButtonPanel);
  240.     progressBar.setValue(++currentProgressValue);
  241.  
  242.     // ToggleButtons
  243.     progressLabel.setText("Loading ToggleButton Example");
  244.     toggleButtonPanel = new ToggleButtonPanel(this);
  245.     tabbedPane.addTab("ToggleButtons", null, toggleButtonPanel);
  246.     progressBar.setValue(++currentProgressValue);
  247.  
  248.     // CheckBoxMenuItem
  249.     progressLabel.setText("Loading Checkbox Example");
  250.     checkboxPanel = new CheckboxPanel(this);
  251.     tabbedPane.addTab("Checkboxes", null, checkboxPanel);
  252.     progressBar.setValue(++currentProgressValue);
  253.  
  254.     // Labels
  255.     progressLabel.setText("Loading Label Example");
  256.     labelPanel = new LabelPanel(this);
  257.     tabbedPane.addTab("Labels", null, labelPanel);
  258.     progressBar.setValue(++currentProgressValue);
  259.  
  260.     // Borders
  261.     progressLabel.setText("Loading Border Example");
  262.     borderPanel = new BorderPanel();
  263.     tabbedPane.addTab("Borders", null, borderPanel);
  264.     progressBar.setValue(++currentProgressValue);
  265.  
  266.     // ComboBox
  267.     progressLabel.setText("Loading ComboBox Example");
  268.     comboBoxPanel = new ComboBoxPanel(this);
  269.     tabbedPane.addTab("ComboBox",null,comboBoxPanel);
  270.     progressBar.setValue(++currentProgressValue);
  271.  
  272.     // DebugGraphics
  273.     progressLabel.setText("Loading DebugGraphics Example");
  274.     debugGraphicsPanel = new DebugGraphicsPanel(this);
  275.     tabbedPane.addTab("DebugGraphics", null, debugGraphicsPanel);
  276.     progressBar.setValue(++currentProgressValue);
  277.  
  278.     // Internal Frame
  279.     progressLabel.setText("Loading Internal Frame Example");
  280.     windowPanel = new InternalWindowPanel();
  281.     tabbedPane.addTab("Internal Frame", null, windowPanel);
  282.     progressBar.setValue(++currentProgressValue);
  283.  
  284.     // ListBox
  285.     progressLabel.setText("Loading ListBox Example");
  286.     listBoxPanel = new ListPanel(this);
  287.     tabbedPane.addTab("ListBox", null, listBoxPanel);
  288.     progressBar.setValue(++currentProgressValue);
  289.  
  290.     // Menus
  291.     progressLabel.setText("Loading Menu Example");
  292.     menuPanel = createMenus();
  293.     tabbedPane.addTab("Menus & ToolBars", null, menuPanel);
  294.     progressBar.setValue(++currentProgressValue);
  295.     // This is unfortunately needed right now, since JMenu
  296.     // has no way to know when an ancestor is removed from
  297.     // the hierarchy so that it can deselect itself.  We
  298.     // do this explicitly here so that menus aren't left
  299.     // hanging when you switch tabs -- better underlying 
  300.     // support will exist in future versions.
  301.     tabbedPane.addContainerListener(new ContainerAdapter() {
  302.         public void componentRemoved(ContainerEvent e) {
  303.         Component c = e.getChild();
  304.         if (c == menuPanel) 
  305.             menuBar.setSelected(null);
  306.         }
  307.  
  308.     });
  309.  
  310.     // ProgressBar
  311.     progressLabel.setText("Loading ProgressBar Example");
  312.     progressBarPanel = new ProgressPanel(this);
  313.     tabbedPane.addTab("ProgressBar", null, progressBarPanel);
  314.     progressBar.setValue(++currentProgressValue);
  315.  
  316.     // ScrollPane
  317.     progressLabel.setText("Loading ScrollPane Example");
  318.     scrollPanePanel = new ScrollPanePanel();
  319.     tabbedPane.addTab("ScrollPane", littleTiger, scrollPanePanel);
  320.     progressBar.setValue(++currentProgressValue);
  321.  
  322.  
  323.     // Sliders
  324.     progressLabel.setText("Loading Slider Example");
  325.     sliderPanel = new SliderPanel(swing);
  326.     tabbedPane.addTab("Slider", null, sliderPanel);
  327.     progressBar.setValue(++currentProgressValue);
  328.  
  329.     // SplitPane
  330.     progressLabel.setText("Loading SplitPane Example");
  331.     splitPanePanel = new SplitPanePanel(this);
  332.     tabbedPane.addTab("SplitPane", null, splitPanePanel);
  333.     progressBar.setValue(++currentProgressValue);
  334.  
  335.  
  336.     // Table
  337.     progressLabel.setText("Loading Table Example");
  338.     tablePanel = new TablePanel(swing);
  339.     tabbedPane.addTab("TableView", null, tablePanel);
  340.     progressBar.setValue(++currentProgressValue);
  341.  
  342.     // Text
  343.     progressLabel.setText("Loading Text Example");
  344.     textPanel = new TextPanel(swing);
  345.     tabbedPane.addTab("Plain Text", null, textPanel);
  346.     progressBar.setValue(++currentProgressValue);
  347.  
  348.     // HTML Text
  349.     // PENDING(jeff) make this work when we are an applet
  350.     if(!isApplet()) {
  351.         progressLabel.setText("Loading HTML Text Example");
  352.         htmlPanel = new HtmlPanel(swing);
  353.         tabbedPane.addTab("HTML Text", null, htmlPanel);
  354.         progressBar.setValue(++currentProgressValue);
  355.     }
  356.  
  357.     // borderedPane
  358.     progressLabel.setText("Loading BorderedPane Example");
  359.     borderedPanePanel = new BorderedPanePanel(this);
  360.     tabbedPane.addTab("BorderedPane", null, borderedPanePanel);
  361.     progressBar.setValue(++currentProgressValue);
  362.  
  363.     // ToolTips
  364.     progressLabel.setText("Loading ToolTip Example");
  365.     toolTipPanel = new ToolTipPanel(swing);
  366.     tabbedPane.addTab("ToolTips", cow, toolTipPanel);
  367.     toolTipIndex = currentProgressValue;
  368.     progressBar.setValue(++currentProgressValue);
  369.  
  370.     // TreeView
  371.     progressLabel.setText("Loading TreeView Example");
  372.     treePanel = new TreePanel(this);
  373.     tabbedPane.addTab("TreeView", null, treePanel);
  374.     progressBar.setValue(++currentProgressValue);
  375.  
  376.     // Add Tab change listener
  377.     createTabListener();
  378.  
  379.     }
  380.  
  381.     class ToggleLogging extends AbstractAction {
  382.         public void actionPerformed(ActionEvent e) {
  383.            Timer.setLogTimers(!Timer.getLogTimers());
  384.         }
  385.  
  386.         public boolean isEnabled() {
  387.             return true;
  388.         }
  389.     }
  390.  
  391.   /** Image loading **/
  392.   void loadImages() {
  393.     jpgIcon = loadImageIcon("images/jpgIcon.jpg", "An icon that represents jpg images");
  394.     gifIcon = loadImageIcon("images/gifIcon.gif", "An icon that represents gif images");
  395.     blueDot   = loadImageIcon("images/dot.gif","A blue bullet icon - to draw attention to a menu item");
  396.     redDot   = loadImageIcon("images/redDot.gif","A red bullet icon - to draw attention to a menu item");
  397.     invisibleDot   = loadImageIcon("images/noDot.gif","An invisible bullet, used in visual spacing of menu items");
  398.     duke2 = loadImageIcon("images/duke2.gif","Duke with hands at sides");
  399.     dukeSnooze = loadImageIcon("images/dukeSnooze.gif","Sleeping Duke");
  400.     dukeWave   = loadImageIcon("images/dukeWave.gif","Duke waving");
  401.     dukeWaveRed = loadImageIcon("images/dukeWaveRed.gif","Duke waving with bright red nose");
  402.     dukeMagnify = loadImageIcon("images/dukeMagnify.gif","Duke with a magnifying glass");
  403.     cow         = loadImageIcon("images/cowSmall.gif","Black and white cow");
  404.     tiger       = loadImageIcon("images/BigTiger.gif","Fierce looking tiger");
  405.     littleTiger = loadImageIcon("images/SmallTiger.gif","Fierce looking tiger");
  406.     upButton    = loadImageIcon("images/buttonImage2.gif","Round button with gold border, green on the inside, and dark triangle pointing right.");
  407.     downButton  = loadImageIcon("images/buttonImage3.gif","Round button with gold border, green on the inside, and green triangle pointing right.");
  408.     disabledButton = loadImageIcon("images/buttonImage4.gif","Round button with gold border, green on the inside, and greyed out triangle pointing right.");
  409.   }
  410.  
  411.     private class AccessibilityEasterListener extends MouseAdapter {
  412.         StringTokenizer descriptionTokens;
  413.         String descriptionText;
  414.     JMenuItem menuItem;
  415.         public AccessibilityEasterListener(JMenuItem mi, String descs) {
  416.         super();
  417.         descriptionTokens = new StringTokenizer(descs, ",");
  418.         descriptionText = descs;
  419.         menuItem = mi;
  420.         }
  421.  
  422.         public void mouseEntered(MouseEvent e) {
  423.             if (!descriptionTokens.hasMoreTokens()) {
  424.             descriptionTokens = new StringTokenizer(descriptionText, ",");
  425.             }
  426.             menuItem.getAccessibleContext().setAccessibleDescription(descriptionTokens.nextToken());
  427.         }
  428.     }
  429.  
  430.     /*******************************************/
  431.     /************ create components ************/
  432.     /*******************************************/
  433.  
  434.     /**
  435.      * MenuBar
  436.      */
  437.     JDialog aboutBox;
  438.     JCheckBoxMenuItem cb;
  439.     JRadioButtonMenuItem rb;
  440.  
  441.     JMenuBar createMenuBar() {
  442.     // MenuBar
  443.     JMenuBar menuBar = new JMenuBar();
  444.     menuBar.getAccessibleContext().setAccessibleName("Swing menus");
  445.  
  446.     JMenuItem mi;
  447.  
  448.     // File Menu
  449.     JMenu file = (JMenu) menuBar.add(new JMenu("File"));
  450.         file.setMnemonic('F');
  451.     file.getAccessibleContext().setAccessibleDescription("The standard 'File' application menu");
  452.         mi = (JMenuItem) file.add(new JMenuItem("About"));
  453.         mi.setMnemonic('t');
  454.     mi.getAccessibleContext().setAccessibleDescription("Find out about the SwingSet application");
  455.     mi.addActionListener(new ActionListener() {
  456.         public void actionPerformed(ActionEvent e) {
  457.         // tabbedPane.setSelectedIndex(0);
  458.                 if(aboutBox == null) {
  459.                     aboutBox = new JDialog(SwingSet.sharedInstance().getFrame(), "About Swing!", false);
  460.                     JPanel groupPanel = new JPanel(new BorderLayout());
  461.             ImageIcon groupPicture = loadImageIcon("images/Copyright.gif",
  462.                       "SwingSet demo is Copyright (c) 1997 Sun Microsystems, Inc.  All Rights Reserved.");
  463.                     aboutBox.getContentPane().add(groupPanel, BorderLayout.CENTER);
  464.             JLabel groupLabel = (new JLabel(groupPicture));
  465.             groupLabel.getAccessibleContext().setAccessibleName("SwingSet demo Copyright");
  466.             groupLabel.getAccessibleContext().setAccessibleDescription("The JFC Swing Toolkit is a cooperative effort between JavaSoft and Netscape.  The SwingSet demo is Copyright 1997 Sun Microsystems, Inc.  All Rights Reserved.");
  467.                     groupPanel.add(groupLabel, BorderLayout.CENTER);
  468.                     JPanel buttonPanel = new JPanel(true);
  469.                     groupPanel.add(buttonPanel, BorderLayout.SOUTH);
  470.                     JButton button = (JButton) buttonPanel.add(new JButton("OK"));
  471.                     button.addActionListener(new ActionListener() {
  472.                         public void actionPerformed(ActionEvent e) {
  473.                             aboutBox.setVisible(false);
  474.                         }
  475.                     });
  476.                 }
  477.         aboutBox.pack();
  478.         aboutBox.show();
  479.         }
  480.     });
  481.  
  482.         file.addSeparator();
  483.         mi = (JMenuItem) file.add(new JMenuItem("Open"));
  484.         mi.setMnemonic('O');
  485.     mi.setEnabled(false);
  486.     mi.getAccessibleContext().setAccessibleDescription("Placeholder sample menu item for opening a file");
  487.         mi = (JMenuItem) file.add(new JMenuItem("Save"));
  488.         mi.setMnemonic('S');
  489.     mi.setEnabled(false);
  490.     mi.getAccessibleContext().setAccessibleDescription("Placeholder sample menu item for saving a file");
  491.         mi = (JMenuItem) file.add(new JMenuItem("Save As..."));
  492.         mi.setMnemonic('A');
  493.     mi.setEnabled(false);
  494.     mi.getAccessibleContext().setAccessibleDescription("Placeholder sample menu item for saving a file with a new name");
  495.         file.addSeparator();
  496.         mi = (JMenuItem) file.add(new JMenuItem("Exit"));
  497.         mi.setMnemonic('x');
  498.     mi.getAccessibleContext().setAccessibleDescription("Exit the SwingSet application");
  499.     mi.addActionListener(new ActionListener() {
  500.         public void actionPerformed(ActionEvent e) {
  501.         System.exit(0);
  502.         }
  503.     }
  504.     );
  505.  
  506.     // Options Menu
  507.     JMenu options = (JMenu) menuBar.add(new JMenu("Options"));
  508.         options.setMnemonic('p');
  509.     options.getAccessibleContext().setAccessibleDescription("Look and Feel options: select one of several different Look and Feels for the SwingSet application");
  510.  
  511.         // Look and Feel Radio control
  512.     ButtonGroup group = new ButtonGroup();
  513.     ToggleUIListener toggleUIListener = new ToggleUIListener();
  514.  
  515.         metalMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Java Look and Feel"));
  516.     metalMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("Metal"));
  517.     metalMenuItem.setSelected(true);
  518.     group.add(metalMenuItem);
  519.     metalMenuItem.addItemListener(toggleUIListener);
  520.     metalMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
  521.  
  522.         motifMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Motif Look and Feel"));
  523.     motifMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("CDE/Motif"));
  524.     group.add(motifMenuItem);
  525.     motifMenuItem.addItemListener(toggleUIListener);
  526.     motifMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
  527.  
  528.         windowsMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Windows Style Look and Feel"));
  529.     windowsMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("Windows"));
  530.     group.add(windowsMenuItem);
  531.     windowsMenuItem.addItemListener(toggleUIListener);
  532.     windowsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK));
  533.  
  534.     // Not shipped yet with full Swing release
  535.         /*
  536.       macMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Macintosh Look and Feel"));
  537.       macMenuItem.setSelected(UIManager.getLookAndFeel().getName().equals("Macintosh"));
  538.       group.add(macMenuItem);
  539.       macMenuItem.addItemListener(toggleUIListener);
  540.       macMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, ActionEvent.ALT_MASK));
  541.     */
  542.  
  543.     // non-supported stuff
  544.     /*  
  545.         rb = (JRadioButtonMenuItem)
  546.             options.add(new JRadioButtonMenuItem("Java Look and Feel (High Contrast Theme)"));
  547.         rb.setSelected(UIManager.getLookAndFeel().getName().equals("Metal HCT"));
  548.         group.add(rb);
  549.         rb.addItemListener(toggleUIListener);
  550.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, ActionEvent.ALT_MASK));
  551.         
  552.         rb = (JRadioButtonMenuItem)
  553.              options.add(new JRadioButtonMenuItem("Organic Look and Feel (Santa Fe)"));
  554.         rb.getAccessibleContext().setAccessibleDescription(
  555.              "The Organic Look and Feel with a brown/yellow color scheme");
  556.         rb.setSelected(UIManager.getLookAndFeel().getName().equals("Java"));
  557.         group.add(rb);
  558.         rb.addItemListener(toggleUIListener);
  559.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, ActionEvent.ALT_MASK));
  560.         
  561.         rb = (JRadioButtonMenuItem)
  562.             options.add(new JRadioButtonMenuItem("Organic Look and Feel (Vancouver)"));
  563.         rb.getAccessibleContext().setAccessibleDescription(
  564.             "The Organic Look and Feel with a neutral grey color scheme");
  565.         group.add(rb);
  566.         rb.addItemListener(toggleUIListener);
  567.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_6, ActionEvent.ALT_MASK));
  568.         
  569.         rb = (JRadioButtonMenuItem)
  570.             options.add(new JRadioButtonMenuItem("Organic Look and Feel (Dallas)"));
  571.         rb.getAccessibleContext().setAccessibleDescription(
  572.             "The Organic Look and Feel with a high contrast color scheme and large print");
  573.         group.add(rb);
  574.         rb.addItemListener(toggleUIListener);
  575.         rb.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_7, ActionEvent.ALT_MASK));
  576.     */
  577.  
  578.         // Tab Placement submenu
  579.         options.addSeparator();
  580.  
  581.         tabPlacement = new TabPlacementChanger();
  582.     tabPlacement.getAccessibleContext().setAccessibleDescription(
  583.            "Sub-menu containing options for placement of the TabbedPane");
  584.         options.add(tabPlacement);
  585.  
  586.         // Tooltip checkbox
  587.         options.addSeparator();
  588.  
  589.         cb = (JCheckBoxMenuItem) options.add(new JCheckBoxMenuItem("Show ToolTips"));
  590.     cb.setSelected(true);
  591.  
  592.     cb.addActionListener(new ActionListener() {
  593.         public void actionPerformed(ActionEvent e) {
  594.         JCheckBoxMenuItem cb = (JCheckBoxMenuItem)e.getSource();
  595.         if(cb.isSelected()) {
  596.                     ToolTipManager.sharedInstance().setEnabled(true);
  597.         } else {
  598.                     ToolTipManager.sharedInstance().setEnabled(false);
  599.         }
  600.         }
  601.     });
  602.  
  603.     ActionListener easterListener = new ActionListener() {
  604.         public void actionPerformed(ActionEvent e) {
  605.         tabbedPane.setSelectedIndex(toolTipIndex);
  606.         ((ToolTipPanel)toolTipPanel).itsEaster(true);
  607.         swing.invalidate();
  608.         swing.validate();
  609.         swing.repaint();
  610.         }
  611.     };
  612.  
  613.     // Contributors Menu
  614.     JMenu people = (JMenu) menuBar.add(new JMenu("The Swing Team"));
  615.         people.setMnemonic('A');
  616.     people.getAccessibleContext().setAccessibleDescription(
  617.             "Listing of all of the individual contributors to Swing");
  618.  
  619.         mi = (JMenuItem) people.add(new JMenuItem("Michael Albers", invisibleDot));
  620.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  621.  
  622.         mi = (JMenuItem) people.add(new JMenuItem("Mark Andrews", invisibleDot));
  623.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  624.  
  625.         mi = (JMenuItem) people.add(new JMenuItem("Tom Ball", redDot));
  626.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  627.     mi.addActionListener(easterListener);
  628.  
  629.         mi = (JMenuItem) people.add(new JMenuItem("Jeff Dinkins", redDot));
  630.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  631.     mi.addActionListener(easterListener);
  632.  
  633.         mi = (JMenuItem) people.add(new JMenuItem("Amy Fowler", redDot));
  634.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  635.     mi.addActionListener(easterListener);
  636.  
  637.         mi = (JMenuItem) people.add(new JMenuItem("James Gosling", redDot));
  638.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  639.     mi.addActionListener(easterListener);
  640.  
  641.         mi = (JMenuItem) people.add(new JMenuItem("Earl Johnson", invisibleDot));
  642.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  643.     mi.addMouseListener(new AccessibilityEasterListener(mi, "Accessibility Program Manager, Founder of Sun's Accessibility Effort"));
  644.  
  645.         mi = (JMenuItem) people.add(new JMenuItem("Will Walker", blueDot));
  646.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  647.     mi.addMouseListener(new AccessibilityEasterListener(mi, "Wrote Java Accessibility API,Wrote AccessX,Designed RAP prototol,Contributor to UltraSonix"));
  648.     mi.addActionListener(new ActionListener() {
  649.         public void actionPerformed(ActionEvent e) {
  650.         tabbedPane.setSelectedIndex(toolTipIndex);
  651.         ((ToolTipPanel)toolTipPanel).itsEaster(false);
  652.         swing.invalidate();
  653.         swing.validate();
  654.         swing.repaint();
  655.         }
  656.     });
  657.  
  658.         mi = (JMenuItem) people.add(new JMenuItem("Peter Korn", invisibleDot));
  659.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  660.     mi.addMouseListener(new AccessibilityEasterListener(mi, "Wrote Accessibility API,Wrote outSPOKEN for Windows,Wrote GUIAccess for Windows,Contributed to outSPOKEN for Macintosh,Contributed to inLARGE for Macintosh"));
  661.  
  662.         mi = (JMenuItem) people.add(new JMenuItem("Rick Levenson", redDot));
  663.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  664.     mi.addActionListener(easterListener);
  665.  
  666.         mi = (JMenuItem) people.add(new JMenuItem("Philip Milne", redDot));
  667.  
  668.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  669.     mi.addActionListener(easterListener);
  670.  
  671.         mi = (JMenuItem) people.add(new JMenuItem("Hans Muller", redDot));
  672.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  673.     mi.addActionListener(easterListener);
  674.  
  675.         mi = (JMenuItem) people.add(new JMenuItem("Tim Prinzing", redDot));
  676.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  677.     mi.addActionListener(easterListener);
  678.  
  679.         mi = (JMenuItem) people.add(new JMenuItem("Chris Ryan", invisibleDot));
  680.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  681.  
  682.         mi = (JMenuItem) people.add(new JMenuItem("Georges Saab", redDot));
  683.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  684.     mi.addActionListener(easterListener);
  685.  
  686.         mi = (JMenuItem) people.add(new JMenuItem("Tom Santos", invisibleDot));
  687.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  688.  
  689.         mi = (JMenuItem) people.add(new JMenuItem("Jeff Shapiro", invisibleDot));
  690.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  691.  
  692.         mi = (JMenuItem) people.add(new JMenuItem("Rich Schiavi", redDot));
  693.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  694.     mi.addActionListener(easterListener);
  695.  
  696.         mi = (JMenuItem) people.add(new JMenuItem("Nancy Schorr", invisibleDot));
  697.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  698.  
  699.         mi = (JMenuItem) people.add(new JMenuItem("Harry Vertelney", invisibleDot));
  700.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  701.  
  702.         mi = (JMenuItem) people.add(new JMenuItem("Scott Violet", redDot));
  703.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  704.  
  705.  
  706.         mi = (JMenuItem) people.add(new JMenuItem("Kathy Walrath", invisibleDot));
  707.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  708.  
  709.         mi = (JMenuItem) people.add(new JMenuItem("Arnaud Weber", redDot));
  710.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  711.     mi.addActionListener(easterListener);
  712.  
  713.         mi = (JMenuItem) people.add(new JMenuItem("Steve Wilson", invisibleDot));
  714.     mi.setHorizontalTextPosition(JMenuItem.RIGHT);
  715.  
  716.     // Chooser Menu
  717.     JMenu choosers = (JMenu) menuBar.add(new JMenu("Choosers"));
  718.     choosers.setMnemonic('H');
  719.     choosers.getAccessibleContext().setAccessibleDescription("Invoke one of the Swing Choosers");
  720.     mi = (JMenuItem) choosers.add(new JMenuItem("Color Chooser"));
  721.     ActionListener startColorChooser = new ActionListener() {
  722.         public void actionPerformed(ActionEvent e) {
  723.         tabbedPane.setSelectedIndex(toolTipIndex);
  724.         Color color = JColorChooser.showDialog(SwingSet.this, "Color Chooser", toolTipPanel.getBackground());
  725.         toolTipPanel.setBackground(color); 
  726.         toolTipPanel.repaint();
  727.         
  728.         }
  729.     };
  730.     mi.addActionListener(startColorChooser);
  731.     
  732.     if(!isApplet()) {
  733.         mi = (JMenuItem) choosers.add(new JMenuItem("File Chooser"));
  734.         ActionListener startFileChooser = new ActionListener() {
  735.         public void actionPerformed(ActionEvent e) {
  736.             JFileChooser chooser = new JFileChooser();
  737.             ExampleFileFilter filter = new ExampleFileFilter(
  738.             new String[] {"jpg", "gif"}, "JPEG and GIF Image Files"
  739.             );
  740.             ExampleFileView fileView = new ExampleFileView();
  741.             fileView.putIcon("jpg", jpgIcon);
  742.             fileView.putIcon("gif", gifIcon);
  743.             chooser.setFileView(fileView);
  744.             chooser.addChoosableFileFilter(filter);
  745.             chooser.setFileFilter(filter);
  746.             chooser.setAccessory(new FilePreviewer(chooser));
  747.  
  748.             File swingFile = new File("images/swing-64.gif");
  749.             if(swingFile.exists()) {
  750.             chooser.setCurrentDirectory(swingFile);
  751.             chooser.setSelectedFile(swingFile);
  752.             } 
  753.  
  754.             int retval = chooser.showOpenDialog(SwingSet.this);
  755.             if(retval == 0) {
  756.             File theFile = chooser.getSelectedFile();
  757.             if(theFile != null) {
  758.                 JOptionPane.showMessageDialog(SwingSet.this, "You chose this file: " +
  759.                               chooser.getSelectedFile().getAbsolutePath());
  760.                 return;
  761.             }
  762.             } 
  763.             JOptionPane.showMessageDialog(SwingSet.this, "No file chosen");
  764.         }
  765.         };
  766.         mi.addActionListener(startFileChooser);
  767.     }
  768.  
  769.     createOptionsMenu(menuBar);
  770.     return menuBar;
  771.     }
  772.  
  773.     /**
  774.      * Menus
  775.      */
  776.     JMenuBar menuBar;
  777.  
  778.     JPanel createMenus() {
  779.     JPanel p = createVerticalPanel(true);
  780.     p.setBorder(emptyBorder10);
  781.  
  782.     // ********************
  783.     // ***** MenuBar ******
  784.     // ********************
  785.     JLabel l = new JLabel("Menus:");
  786.     l.setAlignmentX(LEFT_ALIGNMENT);
  787.     l.setAlignmentY(TOP_ALIGNMENT);
  788.     l.setFont(boldFont);
  789.     p.add(l);
  790.     p.add(Box.createRigidArea(vpad10));
  791.     menuBar = new JMenuBar();
  792.     menuBar.setAlignmentX(LEFT_ALIGNMENT);
  793.     menuBar.setAlignmentY(TOP_ALIGNMENT);
  794.     p.add(menuBar);
  795.     p.add(Box.createRigidArea(vpad40));
  796.     l.setLabelFor(menuBar);    // make label Mnemonic go to menu bar
  797.     l.setDisplayedMnemonic('m');
  798.  
  799.     // File
  800.     JMenu file = (JMenu) menuBar.add(new JMenu("File"));
  801.     file.setMnemonic('i');
  802.     JMenuItem newItem =
  803.     file.add(new JMenuItem("New", loadImageIcon("images/new.gif","New")));
  804.     newItem.setHorizontalTextPosition(JButton.RIGHT);
  805.     newItem.setMnemonic('N');
  806.     JMenuItem open = (JMenuItem)
  807.     file.add(new JMenuItem("Open", loadImageIcon("images/open.gif","Open")));
  808.     open.setHorizontalTextPosition(JButton.RIGHT);
  809.     open.setMnemonic('O');
  810.     JMenuItem save = (JMenuItem)
  811.     file.add(new JMenuItem("Save", loadImageIcon("images/save.gif","Save")));
  812.     save.setHorizontalTextPosition(JButton.RIGHT);
  813.     save.setMnemonic('S');
  814.  
  815.     // Edit
  816.     JMenu edit = (JMenu) menuBar.add(new JMenu("Edit"));
  817.     edit.setMnemonic('E');
  818.     JMenuItem cut = (JMenuItem)
  819.     edit.add(new JMenuItem("Cut", loadImageIcon("images/cut.gif","Cut")));
  820.     cut.setHorizontalTextPosition(JButton.RIGHT);
  821.     cut.setMnemonic('t');
  822.     JMenuItem copy = (JMenuItem)
  823.     edit.add(new JMenuItem("Copy", loadImageIcon("images/copy.gif","Copy")));
  824.     copy.setHorizontalTextPosition(JButton.RIGHT);
  825.     copy.setMnemonic('C');
  826.     JMenuItem paste = (JMenuItem)
  827.     edit.add(new JMenuItem("Paste", loadImageIcon("images/paste.gif","Paste")));
  828.     paste.setHorizontalTextPosition(JButton.RIGHT);
  829.     paste.setMnemonic('P');
  830.  
  831.     // Letters
  832.     JMenu letters = (JMenu) menuBar.add(new JMenu("Letters "));
  833.     letters.setMnemonic('t');
  834.  
  835.     JMenu letterMenu;
  836.     JMenu subMenu;
  837.         JMenu tmpMenu;
  838.  
  839.     // C
  840.         letterMenu = (JMenu) letters.add((tmpMenu = new JMenu("A")));
  841.         tmpMenu.setMnemonic('A');
  842.         subMenu = (JMenu) letterMenu.add(new JMenu("A is for Airplane"));
  843.           subMenu.add(new JMenuItem("Cessna 152"));
  844.           subMenu.add(new JMenuItem("Boeing 747"));
  845.           subMenu.add(new JMenuItem("Piper Cherokee"));
  846.  
  847.         subMenu = (JMenu) letterMenu.add(new JMenu("A is for Alicia Silverstone"));
  848.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Clueless"));
  849.       cb.setSelected(true);
  850.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Batman"));
  851.  
  852.         subMenu = (JMenu) letterMenu.add(new JMenu("A is for Apple"));
  853.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Fuji"));
  854.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Granny Smith"));
  855.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Macintosh"));
  856.       cb.setSelected(true);
  857.  
  858.     // B
  859.         letterMenu = (JMenu) letters.add((tmpMenu = new JMenu("B")));
  860.         tmpMenu.setMnemonic('B');
  861.         subMenu = (JMenu) letterMenu.add(new JMenu("B is for Swing Babies!"));
  862.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Ewan"));
  863.       cb.setSelected(true);
  864.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Matthew"));
  865.       cb.setSelected(true);
  866.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Montana"));
  867.       cb.setSelected(true);
  868.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Nathan"));
  869.       cb.setSelected(true);
  870.  
  871.         subMenu = (JMenu) letterMenu.add(new JMenu("B is for Band"));
  872.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Alice In Chains"));
  873.       cb.setSelected(true);
  874.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("King Crimson"));
  875.       cb.setSelected(true);
  876.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Meat Puppets"));
  877.       cb.setSelected(true);
  878.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Rush"));
  879.       cb.setSelected(true);
  880.  
  881.         subMenu = (JMenu) letterMenu.add(new JMenu("B is for Baywatch"));
  882.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Pam Anderson"));
  883.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("David Hasslehoff"));
  884.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Yasmine Bleeth"));
  885.       cb.setSelected(true);
  886.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Carmine Electra"));
  887.  
  888.     // C
  889.         letterMenu = (JMenu) letters.add((tmpMenu = new JMenu("C")));
  890.         tmpMenu.setMnemonic('c');
  891.         subMenu = (JMenu) letterMenu.add(new JMenu("C is for Cookie"));
  892.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Chocolate Chip"));
  893.       cb.setSelected(true);
  894.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Fortune"));
  895.       cb.setSelected(true);
  896.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Oatmeal"));
  897.       cb.setSelected(true);
  898.  
  899.         subMenu = (JMenu) letterMenu.add(new JMenu("C is for Cool"));
  900.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("James Dean"));
  901.       cb.setSelected(true);
  902.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("The Fonz"));
  903.       cb.setSelected(true);
  904.  
  905.         subMenu = (JMenu) letterMenu.add(new JMenu("C is for Cats"));
  906.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Ridley"));
  907.       cb.setSelected(true);
  908.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Quigley"));
  909.       cb.setSelected(true);
  910.           cb = (JCheckBoxMenuItem) subMenu.add(new JCheckBoxMenuItem("Kizmet "));
  911.       cb.setSelected(true);
  912.  
  913.  
  914.     // Colors
  915.     JMenu colors = (JMenu) menuBar.add(new JMenu("Colors"));
  916.     colors.setMnemonic('C');
  917.     colors.setHorizontalTextPosition(JButton.RIGHT);
  918.     colors.setIcon(new ColoredSquare(Color.orange));
  919.     menuBar.validate();
  920.  
  921.         JMenuItem red = colors.add(new JMenuItem("Red"));
  922.     red.setHorizontalTextPosition(JButton.RIGHT);
  923.     red.setIcon(new ColoredSquare(Color.red));
  924.  
  925.         JMenuItem blue = colors.add(new JMenuItem("Blue"));
  926.     blue.setHorizontalTextPosition(JButton.RIGHT);
  927.     blue.setIcon(new ColoredSquare(Color.blue));
  928.  
  929.         JMenuItem green = colors.add(new JMenuItem("Green"));
  930.     green.setHorizontalTextPosition(JButton.RIGHT);
  931.     green.setIcon(new ColoredSquare(Color.green));
  932.  
  933.         JMenuItem yellow = colors.add(new JMenuItem("Yellow"));
  934.     yellow.setHorizontalTextPosition(JButton.RIGHT);
  935.     yellow.setIcon(new ColoredSquare(Color.yellow));
  936.  
  937.     // Numbers
  938.     JMenu numbers = (JMenu) menuBar.add(new JMenu("Numbers"));
  939.     numbers.setMnemonic('u');
  940.         numbers.add(new JMenuItem("1234"));
  941.         numbers.add(new JMenuItem("1005"));
  942.         numbers.add(new JMenuItem("2222"));
  943.  
  944.     JMenu drinks = (JMenu) menuBar.add(new JMenu("Drinks"));
  945.     drinks.setMnemonic('D');
  946.         drinks.add(new JMenuItem("Thai Iced Tea"));
  947.         drinks.add(new JMenuItem("Root Beer"));
  948.         drinks.add(new JMenuItem("Green Tea"));
  949.         drinks.add(new JMenuItem("Apple Juice"));
  950.     drinks.addSeparator();
  951.     ImageIcon softdrink = 
  952.              loadImageIcon("images/ImageClub/food/softdrink.gif","soft drink");
  953.         drinks.add(new JMenuItem("Softdrink", softdrink));
  954.  
  955.     JMenu music = (JMenu) menuBar.add(new JMenu("Music"));
  956.     music.setMnemonic('s');
  957.         music.add(new JMenuItem("Rock"));
  958.         music.add(new JMenuItem("Country"));
  959.         music.add(new JMenuItem("Classical"));
  960.         music.add(new JMenuItem("Jazz"));
  961.  
  962.     JMenu food = (JMenu) menuBar.add(new JMenu("Junk Food"));
  963.     food.setMnemonic('J');
  964.     ImageIcon burger = loadImageIcon("images/ImageClub/food/burger.gif","burger");
  965.     ImageIcon fries  = loadImageIcon("images/ImageClub/food/fries.gif","fries");
  966.     ImageIcon hotdog = loadImageIcon("images/ImageClub/food/hotdog.gif","hot dog");
  967.     ImageIcon pizza  = loadImageIcon("images/ImageClub/food/pizza.gif","pizza");
  968.  
  969.         addMenuItem(food, "Burger", burger);
  970.     addMenuItem(food, "Fries", fries);
  971.     addMenuItem(food, "Hotdog", hotdog);
  972.     addMenuItem(food, "Pizza", pizza);
  973.  
  974.     // ********************
  975.     // ****** ToolBar *****
  976.     // ********************
  977.     l = new JLabel("ToolBar:");
  978.     l.setFont(boldFont);
  979.     l.setAlignmentX(LEFT_ALIGNMENT);
  980.     l.setAlignmentY(TOP_ALIGNMENT);
  981.     p.add(l);
  982.     p.add(Box.createRigidArea(vpad10));
  983.  
  984.     JPanel p1 = (JPanel)p.add(new JPanel());
  985.     p1.setAlignmentX(LEFT_ALIGNMENT);
  986.     p1.setAlignmentY(TOP_ALIGNMENT);
  987.  
  988.     p1.setLayout(new BorderLayout());
  989.     JToolBar toolBar = new JToolBar();
  990.     addTool(toolBar, "new");
  991.     toolBar.addSeparator( new Dimension(3,3) );
  992.     addTool(toolBar, "open");
  993.     toolBar.addSeparator( new Dimension(3,3) );
  994.     addTool(toolBar, "save");
  995.     toolBar.addSeparator( new Dimension(5,5) );
  996.     toolBar.addSeparator( new Dimension(5,5) );
  997.     addTool(toolBar, "cut");
  998.     toolBar.addSeparator( new Dimension(3,3) );
  999.     addTool(toolBar, "copy");
  1000.     toolBar.addSeparator( new Dimension(3,3) );
  1001.     addTool(toolBar, "paste");
  1002.  
  1003.     toolBar.putClientProperty( "JToolBar.isRollover", Boolean.FALSE );
  1004.     l.setLabelFor(toolBar);  // make label Mnemonic go to toolbar
  1005.     l.setDisplayedMnemonic('B');
  1006.  
  1007.     p1.add(toolBar, BorderLayout.NORTH);
  1008.  
  1009.     JPanel textWrapper = new JPanel(new BorderLayout());
  1010.     textWrapper.setAlignmentX(LEFT_ALIGNMENT);
  1011.      textWrapper.setBorder(swing.loweredBorder);
  1012.     
  1013.     p1.add(textWrapper, BorderLayout.CENTER);
  1014.  
  1015.     String text = SwingSet.contentsOfFile("ToolBar.txt");
  1016.     JTextArea textArea = new JTextArea(text);
  1017.     textArea.getAccessibleContext().setAccessibleName("ToolBar information");
  1018.     JScrollPane scroller = new JScrollPane() {
  1019.         public Dimension getPreferredSize() {
  1020.         return new Dimension(10,10);
  1021.         }
  1022.         public float getAlignmentX() {
  1023.         return LEFT_ALIGNMENT;
  1024.         }
  1025.     };
  1026.     scroller.getViewport().add(textArea);
  1027.     textArea.setFont(new Font("Dialog", Font.PLAIN, 12));
  1028.     textWrapper.add(scroller, BorderLayout.CENTER);
  1029.     
  1030.     textArea.setEditable(false);
  1031.     return p;
  1032.     }
  1033.  
  1034.     void createOptionsMenu(JMenuBar menuBar) {
  1035.     JMenu optionMenu = (JMenu)menuBar.add(new JMenu("Dialogs"));
  1036.         optionMenu.setMnemonic('D');
  1037.     JMenuItem item;
  1038.     item = new JMenuItem("Message Dialog");
  1039.     item.addActionListener(new ActionListener() {
  1040.         public void actionPerformed(ActionEvent e) {
  1041.         JOptionPane.showMessageDialog(SwingSet.this, "Plain message");
  1042.         }
  1043.     });
  1044.     optionMenu.add(item);
  1045.  
  1046.     item = new JMenuItem("Warning Dialog");
  1047.     item.addActionListener(new ActionListener() {
  1048.         public void actionPerformed(ActionEvent e) {
  1049.         JOptionPane.showMessageDialog(SwingSet.this, "Example Warning",
  1050.                     "Warning", JOptionPane.WARNING_MESSAGE);
  1051.         }
  1052.     });
  1053.     optionMenu.add(item);
  1054.  
  1055.     item = new JMenuItem("Confirmation Dialog");
  1056.     item.addActionListener(new ActionListener() {
  1057.         public void actionPerformed(ActionEvent e) {
  1058.         int        result;
  1059.         result = JOptionPane.showConfirmDialog(SwingSet.this, "Is SWING cool?");
  1060.         if(result == JOptionPane.YES_OPTION)
  1061.             JOptionPane.showMessageDialog(SwingSet.this, "All right!");
  1062.         else if(result == JOptionPane.NO_OPTION)
  1063.             JOptionPane.showMessageDialog(SwingSet.this, "That is too bad, please send us email describing what you don't like and how we can change it.");
  1064.         }
  1065.     });
  1066.     optionMenu.add(item);
  1067.  
  1068.     item = new JMenuItem("Input Dialog");
  1069.     item.addActionListener(new ActionListener() {
  1070.         public void actionPerformed(ActionEvent e) {
  1071.         String          result;
  1072.  
  1073.         result = JOptionPane.showInputDialog(SwingSet.this, "Please enter your name:");
  1074.         if(result != null) {
  1075.             Object[] message = new Object[2];
  1076.             message[0] = "Thank you for using SWING ";
  1077.             message[1] = result;
  1078.             JOptionPane.showMessageDialog(SwingSet.this, message);
  1079.         }
  1080.         }
  1081.     });
  1082.     optionMenu.add(item);
  1083.  
  1084.     item = new JMenuItem("Component Dialog");
  1085.     item.addActionListener(new ActionListener() {
  1086.         public void actionPerformed(ActionEvent e) {
  1087.         Object[]      message = new Object[4];
  1088.                 JComboBox cb = new JComboBox();
  1089.                 cb.addItem("One");
  1090.                 cb.addItem("Two");
  1091.                 cb.addItem("Three");
  1092.         message[0] = "JOptionPane can contain any number of components, and any number options.";
  1093.         message[1] = new JButton("a button");
  1094.         message[2] = new JTextField("a text field");
  1095.                 message[3] = cb;
  1096.                 
  1097.  
  1098.         String[]      options = { "Option 1", "Option 2", "Option 3",
  1099.                       "Option 4" };
  1100.         JOptionPane.showOptionDialog(SwingSet.this, message, "Example", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[1]);
  1101.         }
  1102.     });
  1103.     optionMenu.add(item);
  1104.     }
  1105.     
  1106.  
  1107.     void addMenuItem(JMenu menu, String text, Icon g) {
  1108.     JMenuItem mi = menu.add(new JMenuItem(text, g));
  1109.     mi.setHorizontalTextPosition(JButton.CENTER);
  1110.     mi.setHorizontalAlignment(JButton.LEFT);
  1111.     mi.setVerticalTextPosition(JButton.BOTTOM);
  1112.     }
  1113.  
  1114.     public void addTool(JToolBar toolBar, String name) {
  1115.     JButton b = 
  1116.            (JButton) toolBar.add(
  1117.                new JButton(loadImageIcon("images/" + name + ".gif",name)));
  1118.     b.setToolTipText(name);
  1119.     b.setMargin(insets0);
  1120.     b.getAccessibleContext().setAccessibleName(name);
  1121.     }
  1122.  
  1123.     /**
  1124.      * Text
  1125.      */
  1126.     JPanel createText() {
  1127.     return new JPanel();
  1128.     }
  1129.  
  1130.     /**
  1131.      * Tab Listener
  1132.      */
  1133.     void createTabListener() {
  1134.     // add listener to know when we've been shown
  1135.         ChangeListener changeListener = new ChangeListener() {
  1136.             public void stateChanged(ChangeEvent e) {
  1137.                 JTabbedPane tab = (JTabbedPane) e.getSource();
  1138.                 int index = tab.getSelectedIndex();
  1139.                 Component currentPage = tab.getComponentAt(index);
  1140.         RepaintManager repaintManager = 
  1141.                     RepaintManager.currentManager(instance);
  1142.  
  1143.         if(!repaintManager.isDoubleBufferingEnabled()) {
  1144.           repaintManager.setDoubleBufferingEnabled(true);
  1145.         }
  1146.  
  1147.         if(previousPage == debugGraphicsPanel) {
  1148.             ((DebugGraphicsPanel)debugGraphicsPanel).resetAll();
  1149.         }
  1150.  
  1151.                 if(currentPage == buttonPanel) {
  1152.             currentControls = buttons;
  1153.         } else if(currentPage == radioButtonPanel) {
  1154.             currentControls = radioButtons;
  1155.         } else if(currentPage == toggleButtonPanel) {
  1156.             currentControls = toggleButtons;
  1157.         } else if(currentPage == checkboxPanel) {
  1158.             currentControls = checkboxes;
  1159.         } else if(currentPage == listBoxPanel) {
  1160.             ((ListPanel)listBoxPanel).resetAll();
  1161.         } else if(currentPage == debugGraphicsPanel) {
  1162.             repaintManager.setDoubleBufferingEnabled(false);
  1163.             invalidate();
  1164.             validate();
  1165.         } else if(currentPage == labelPanel) {
  1166.             currentControls = labels;
  1167.                 }
  1168.                 previousPage = currentPage;
  1169.             }
  1170.         };
  1171.         tabbedPane.addChangeListener(changeListener);
  1172.     }
  1173.  
  1174.  
  1175.  
  1176.     /**
  1177.      *
  1178.      */
  1179.     JPanel createControllButtons() {
  1180.     JPanel p = new JPanel();
  1181.     p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  1182.     p.setBorder(emptyBorder5);
  1183.  
  1184.     return p;
  1185.     }
  1186.  
  1187.     /**
  1188.      * create Logo
  1189.      */
  1190.     JPanel createLogo() {
  1191.     JPanel p = new JPanel();
  1192.     p.setLayout(new BorderLayout());
  1193.     ImageIcon logo = loadImageIcon("images/AboutSwing.gif","Swing!");
  1194.     JLabel logoLabel = new JLabel(logo);
  1195.     logoLabel.getAccessibleContext().setAccessibleName("Swing!");
  1196.     p.add(logoLabel, BorderLayout.CENTER);
  1197.     p.setBorder(new MatteBorder(6,6,6,6, SwingSet.sharedInstance().loadImageIcon("images/AboutBorder.gif","About Box Border")));
  1198.  
  1199.     return p;
  1200.     }
  1201.  
  1202.  
  1203.     public static void main(String[] args) {
  1204.         String vers = System.getProperty("java.version");
  1205.         if (vers.compareTo("1.1.2") < 0) {
  1206.             System.out.println("!!!WARNING: Swing must be run with a " +
  1207.                                "1.1.2 or higher version VM!!!");
  1208.         }
  1209.  
  1210.     // Force SwingSet to come up in the Cross Platform L&F
  1211.     try {
  1212.         UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  1213.         // If you want the System L&F instead, comment out the above line and
  1214.         // uncomment the following:
  1215.         // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  1216.     } catch (Exception exc) {
  1217.         System.out.println("Error loading L&F: " + exc);
  1218.     }
  1219.  
  1220.     WindowListener l = new WindowAdapter() {
  1221.         public void windowClosing(WindowEvent e) {System.exit(0);}
  1222.     };
  1223.  
  1224.     frame = new JFrame("SwingSet");
  1225.     frame.addWindowListener(l);
  1226.     frame.getAccessibleContext().setAccessibleDescription("A sample application to demonstrate the Swing UI components");
  1227.  
  1228.     JOptionPane.setRootFrame(frame);
  1229.  
  1230.     JPanel progressPanel = new JPanel() {
  1231.         public Insets getInsets() {
  1232.         return new Insets(40,30,20,30);
  1233.         }
  1234.     };
  1235.     progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
  1236.     frame.getContentPane().add(progressPanel, BorderLayout.CENTER);
  1237.  
  1238.     Dimension d = new Dimension(400, 20);
  1239.     SwingSet.progressLabel = new JLabel("Loading, please wait...");
  1240.     SwingSet.progressLabel.setAlignmentX(CENTER_ALIGNMENT);
  1241.     SwingSet.progressLabel.setMaximumSize(d);
  1242.     SwingSet.progressLabel.setPreferredSize(d);
  1243.     progressPanel.add(progressLabel);
  1244.     progressPanel.add(Box.createRigidArea(new Dimension(1,20)));
  1245.  
  1246.     SwingSet.progressBar = new JProgressBar(0, SwingSet.totalPanels);
  1247.     SwingSet.progressBar.setStringPainted(true);
  1248.     SwingSet.progressLabel.setLabelFor(progressBar);
  1249.     SwingSet.progressBar.setAlignmentX(CENTER_ALIGNMENT);
  1250.     SwingSet.progressBar.getAccessibleContext().setAccessibleName("SwingSet loading progress");
  1251.     progressPanel.add(SwingSet.progressBar);
  1252.  
  1253.     // show the frame
  1254.     frame.setSize(INITIAL_WIDTH, INITIAL_HEIGHT);
  1255.     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  1256.     frame.setLocation(screenSize.width/2 - INITIAL_WIDTH/2,
  1257.               screenSize.height/2 - INITIAL_HEIGHT/2);
  1258.     frame.show();
  1259.  
  1260.         frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  1261.  
  1262.     SwingSet sw = new SwingSet();
  1263.     frame.getContentPane().removeAll();
  1264.     frame.getContentPane().setLayout(new BorderLayout());
  1265.     frame.getContentPane().add(sw, BorderLayout.CENTER);
  1266.     frame.setLocation(screenSize.width/2 - WIDTH/2,
  1267.               screenSize.height/2 - HEIGHT/2);
  1268.  
  1269.     frame.setSize(WIDTH, HEIGHT);
  1270.     frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  1271.  
  1272.     frame.validate();
  1273.     frame.repaint();
  1274.         sw.requestDefaultFocus();
  1275.     }
  1276.  
  1277.  
  1278.     // Position
  1279.     void setNWposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.LEFT);   b.setVerticalTextPosition(AbstractButton.TOP);}
  1280.     void setNposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.CENTER); b.setVerticalTextPosition(AbstractButton.TOP);}
  1281.     void setNEposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.RIGHT);  b.setVerticalTextPosition(AbstractButton.TOP);}
  1282.     void setWposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.LEFT);   b.setVerticalTextPosition(AbstractButton.CENTER);}
  1283.     void setCposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.CENTER); b.setVerticalTextPosition(AbstractButton.CENTER);}
  1284.     void setEposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.RIGHT);  b.setVerticalTextPosition(AbstractButton.CENTER);}
  1285.     void setSWposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.LEFT);   b.setVerticalTextPosition(AbstractButton.BOTTOM);}
  1286.     void setSposition(AbstractButton b)  {b.setHorizontalTextPosition(AbstractButton.CENTER); b.setVerticalTextPosition(AbstractButton.BOTTOM);}
  1287.     void setSEposition(AbstractButton b) {b.setHorizontalTextPosition(AbstractButton.RIGHT);  b.setVerticalTextPosition(AbstractButton.BOTTOM);}
  1288.  
  1289.     void setNWposition(JLabel b) {b.setHorizontalTextPosition(JLabel.LEFT);   b.setVerticalTextPosition(JLabel.TOP);}
  1290.     void setNposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.CENTER); b.setVerticalTextPosition(JLabel.TOP);}
  1291.     void setNEposition(JLabel b) {b.setHorizontalTextPosition(JLabel.RIGHT);  b.setVerticalTextPosition(JLabel.TOP);}
  1292.     void setWposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.LEFT);   b.setVerticalTextPosition(JLabel.CENTER);}
  1293.     void setCposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.CENTER); b.setVerticalTextPosition(JLabel.CENTER);}
  1294.     void setEposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.RIGHT);  b.setVerticalTextPosition(JLabel.CENTER);}
  1295.     void setSWposition(JLabel b) {b.setHorizontalTextPosition(JLabel.LEFT);   b.setVerticalTextPosition(JLabel.BOTTOM);}
  1296.     void setSposition(JLabel b)  {b.setHorizontalTextPosition(JLabel.CENTER); b.setVerticalTextPosition(JLabel.BOTTOM);}
  1297.     void setSEposition(JLabel b) {b.setHorizontalTextPosition(JLabel.RIGHT);  b.setVerticalTextPosition(JLabel.BOTTOM);}
  1298.  
  1299.     // Alignment
  1300.     void setNWalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.LEFT);   b.setVerticalAlignment(AbstractButton.TOP);}
  1301.     void setNalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.CENTER); b.setVerticalAlignment(AbstractButton.TOP);}
  1302.     void setNEalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.RIGHT);  b.setVerticalAlignment(AbstractButton.TOP);}
  1303.     void setWalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.LEFT);   b.setVerticalAlignment(AbstractButton.CENTER);}
  1304.     void setCalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.CENTER); b.setVerticalAlignment(AbstractButton.CENTER);}
  1305.     void setEalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.RIGHT);  b.setVerticalAlignment(AbstractButton.CENTER);}
  1306.     void setSWalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.LEFT);   b.setVerticalAlignment(AbstractButton.BOTTOM);}
  1307.     void setSalignment(AbstractButton b)  {b.setHorizontalAlignment(AbstractButton.CENTER); b.setVerticalAlignment(AbstractButton.BOTTOM);}
  1308.     void setSEalignment(AbstractButton b) {b.setHorizontalAlignment(AbstractButton.RIGHT);  b.setVerticalAlignment(AbstractButton.BOTTOM);}
  1309.  
  1310.     void setNWalignment(JLabel b) {b.setHorizontalAlignment(JLabel.LEFT);   b.setVerticalAlignment(JLabel.TOP);}
  1311.     void setNalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.CENTER); b.setVerticalAlignment(JLabel.TOP);}
  1312.     void setNEalignment(JLabel b) {b.setHorizontalAlignment(JLabel.RIGHT);  b.setVerticalAlignment(JLabel.TOP);}
  1313.     void setWalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.LEFT);   b.setVerticalAlignment(JLabel.CENTER);}
  1314.     void setCalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.CENTER); b.setVerticalAlignment(JLabel.CENTER);}
  1315.     void setEalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.RIGHT);  b.setVerticalAlignment(JLabel.CENTER);}
  1316.     void setSWalignment(JLabel b) {b.setHorizontalAlignment(JLabel.LEFT);   b.setVerticalAlignment(JLabel.BOTTOM);}
  1317.     void setSalignment(JLabel b)  {b.setHorizontalAlignment(JLabel.CENTER); b.setVerticalAlignment(JLabel.BOTTOM);}
  1318.     void setSEalignment(JLabel b) {b.setHorizontalAlignment(JLabel.RIGHT);  b.setVerticalAlignment(JLabel.BOTTOM);}
  1319.  
  1320.     /**
  1321.      * Switch the between the Windows, Motif, Mac, and the Java Look and Feel
  1322.      */
  1323.     class ToggleUIListener implements ItemListener {
  1324.     public void itemStateChanged(ItemEvent e) {
  1325.         Component root = SwingSet.sharedInstance().getRootComponent();
  1326.         root.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  1327.         JRadioButtonMenuItem rb = (JRadioButtonMenuItem) e.getSource();
  1328.             try {
  1329.            if(rb.isSelected() && rb.getText().equals("Windows Style Look and Feel")) {
  1330.            currentUI = "Windows";
  1331.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  1332.                    tabPlacement.setEnabled(true);
  1333.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1334.            } else if(rb.isSelected() && rb.getText().equals("Macintosh Look and Feel")) {
  1335.            currentUI = "Macintosh";
  1336.                UIManager.setLookAndFeel("javax.swing.plaf.mac.MacLookAndFeel");
  1337.                    tabPlacement.setEnabled(false);
  1338.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1339.            } else if(rb.isSelected() && rb.getText().equals("Motif Look and Feel")) {
  1340.            currentUI = "Motif";
  1341.                UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  1342.                    tabPlacement.setEnabled(true);
  1343.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1344.            } else if(rb.isSelected() && rb.getText().equals("Java Look and Feel")) {
  1345.            currentUI = "Metal";
  1346.                    // javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(
  1347.            //      new javax.swing.plaf.metal.DefaultMetalTheme());
  1348.                UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  1349.                    tabPlacement.setEnabled(true);
  1350.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1351.            } 
  1352.            /* non-supported stuff
  1353.            else if(rb.isSelected() && rb.getText().equals(
  1354.                   "Java Look and Feel (High Contrast Theme)")) {
  1355.                javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(
  1356.               new javax.swing.plaf.metal.ContrastMetalTheme());
  1357.                UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  1358.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1359.            } else if(rb.isSelected() && rb.getText().equals("Organic Look and Feel (Santa Fe)")) {
  1360.                javax.swing.plaf.organic.OrganicLookAndFeel.setCurrentTheme(
  1361.               new javax.swing.plaf.organic.OrganicDefaultTheme());
  1362.                UIManager.setLookAndFeel("javax.swing.plaf.organic.OrganicLookAndFeel");
  1363.                    tabPlacement.setEnabled(true);
  1364.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1365.            } else if(rb.isSelected() && rb.getText().equals("Organic Look and Feel (Vancouver)")) {
  1366.                javax.swing.plaf.organic.OrganicLookAndFeel.setCurrentTheme(
  1367.               new javax.swing.plaf.organic.OrganicGrayTheme());
  1368.                UIManager.setLookAndFeel("javax.swing.plaf.organic.OrganicLookAndFeel");
  1369.                    tabPlacement.setEnabled(true);
  1370.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1371.            } else if(rb.isSelected() && rb.getText().equals("Organic Look and Feel (Dallas)")) {
  1372.                javax.swing.plaf.organic.OrganicLookAndFeel.setCurrentTheme(
  1373.               new javax.swing.plaf.organic.OrganicBigTheme());
  1374.                UIManager.setLookAndFeel("javax.swing.plaf.organic.OrganicLookAndFeel");
  1375.                    tabPlacement.setEnabled(true);
  1376.                SwingUtilities.updateComponentTreeUI(getRootComponent());
  1377.            }
  1378.                */
  1379.             } catch (UnsupportedLookAndFeelException exc) {
  1380.         // Error - unsupported L&F
  1381.         rb.setEnabled(false);
  1382.                 System.err.println("Unsupported LookAndFeel: " + rb.getText());
  1383.         
  1384.         // Set L&F to JLF
  1385.         try {
  1386.             currentUI = "Metal";
  1387.             metalMenuItem.setSelected(true);
  1388.             UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  1389.             tabPlacement.setEnabled(true);
  1390.             SwingUtilities.updateComponentTreeUI(getRootComponent());
  1391.         } catch (Exception exc2) {
  1392.           exc2.printStackTrace();
  1393.             System.err.println("Could not load LookAndFeel: " + exc2);
  1394.             exc2.printStackTrace();
  1395.         }
  1396.             } catch (Exception exc) {
  1397.                 rb.setEnabled(false);
  1398.           exc.printStackTrace();
  1399.                 System.err.println("Could not load LookAndFeel: " + rb.getText());
  1400.         exc.printStackTrace();
  1401.             }
  1402.  
  1403.         root.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  1404.     }
  1405.  
  1406.     }
  1407.             
  1408.  
  1409.    class TabPlacementChanger extends JMenu implements ItemListener {
  1410.        JRadioButtonMenuItem topRb, leftRb, rightRb, bottomRb;
  1411.  
  1412.        public TabPlacementChanger() {
  1413.            super("Tab Placement");
  1414.  
  1415.            ButtonGroup tabGroup = new ButtonGroup();
  1416.  
  1417.            topRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Top"));
  1418.        topRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the top of the window");
  1419.            topRb.setSelected(true);
  1420.            topRb.addItemListener(this);
  1421.            tabGroup.add(topRb);
  1422.         
  1423.            leftRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Left"));
  1424.        leftRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the left of the window");
  1425.            leftRb.addItemListener(this);
  1426.            tabGroup.add(leftRb);
  1427.  
  1428.            bottomRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Bottom"));
  1429.        bottomRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the bottom of the window");
  1430.            bottomRb.addItemListener(this);
  1431.            tabGroup.add(bottomRb);
  1432.  
  1433.            rightRb = (JRadioButtonMenuItem)add(new JRadioButtonMenuItem("Right"));
  1434.        rightRb.getAccessibleContext().setAccessibleDescription("Position the TabbedPane on the right of the window");
  1435.            rightRb.addItemListener(this);
  1436.            tabGroup.add(rightRb);
  1437.         }
  1438.  
  1439.     public void itemStateChanged(ItemEvent e) {
  1440.         JRadioButtonMenuItem rb = (JRadioButtonMenuItem) e.getSource();
  1441.             if (rb.isSelected()) {
  1442.                 String selected = rb.getText();
  1443.                 int placement;
  1444.                 if (selected.equals("Top")) {
  1445.                     placement = JTabbedPane.TOP;
  1446.                 } else if (selected.equals("Left")) {
  1447.                     placement = JTabbedPane.LEFT;
  1448.                 } else if (selected.equals("Bottom")) {
  1449.                     placement = JTabbedPane.BOTTOM;
  1450.                 } else {
  1451.                     placement = JTabbedPane.RIGHT;
  1452.                 }
  1453.                 tabbedPane.setTabPlacement(placement);
  1454.                 tabbedPane.validate();
  1455.             }
  1456.         }
  1457.         public void setEnabled(boolean enabled) {
  1458.             super.setEnabled(enabled);
  1459.             if (!enabled) {
  1460.                 topRb.setSelected(true);
  1461.             } else {
  1462.                 int placement = tabbedPane.getTabPlacement();
  1463.                 switch(placement) {
  1464.                   case JTabbedPane.TOP:
  1465.                       topRb.setSelected(true);
  1466.                       break;
  1467.                   case JTabbedPane.LEFT:
  1468.                       leftRb.setSelected(true);
  1469.                       break;
  1470.                   case JTabbedPane.BOTTOM:
  1471.                       bottomRb.setSelected(true);
  1472.                       break;
  1473.                   case JTabbedPane.RIGHT:
  1474.                       rightRb.setSelected(true);
  1475.                       break;
  1476.                   default:
  1477.                 }
  1478.             }
  1479.         }
  1480.     }
  1481.                     
  1482.  
  1483.     // ***********************************************************
  1484.     // *********** Create the button controls listeners **********
  1485.     // ***********************************************************
  1486.     ItemListener buttonPadListener = new ItemListener() {
  1487.     Component c;
  1488.     AbstractButton b;
  1489.  
  1490.     public void itemStateChanged(ItemEvent e) {
  1491.         // *** pad = 0
  1492.         int pad = -1;
  1493.         JRadioButton rb = (JRadioButton) e.getSource();
  1494.         if(rb.getText().equals("0") && rb.isSelected()) {
  1495.         pad = 0;
  1496.         } else if(rb.getText().equals("10") && rb.isSelected()) {
  1497.         pad = 10;
  1498.         } 
  1499.  
  1500.         for(int i = 0; i < currentControls.size(); i++) {
  1501.         b = (AbstractButton) currentControls.elementAt(i);
  1502.         if(pad == -1) {
  1503.             b.setMargin(null);
  1504.         } else if(pad == 0) {
  1505.             b.setMargin(insets0);
  1506.         } else {
  1507.             b.setMargin(insets10);
  1508.         }
  1509.         }
  1510.         int index = tabbedPane.getSelectedIndex();
  1511.         Component currentPage = tabbedPane.getComponentAt(index);
  1512.         currentPage.invalidate();
  1513.         currentPage.validate();
  1514.         currentPage.repaint();
  1515.     }
  1516.     };
  1517.  
  1518.     ItemListener buttonDisplayListener = new ItemListener() {
  1519.     Component c;
  1520.     AbstractButton b;
  1521.  
  1522.     public void itemStateChanged(ItemEvent e) {
  1523.         JCheckBox cb = (JCheckBox) e.getSource();
  1524.         if(cb.getText().equals("Enabled")) {
  1525.         for(int i = 0; i < currentControls.size(); i++) {
  1526.             c = (Component) currentControls.elementAt(i);
  1527.             c.setEnabled(cb.isSelected());
  1528.             c.invalidate();
  1529.         }
  1530.         } else if(cb.getText().equals("Paint Border")) {
  1531.         c = (Component) currentControls.elementAt(0);
  1532.         if(c instanceof AbstractButton) {
  1533.             for(int i = 0; i < currentControls.size(); i++) {
  1534.             b = (AbstractButton) currentControls.elementAt(i);
  1535.             b.setBorderPainted(cb.isSelected());
  1536.                 b.invalidate();
  1537.             }
  1538.         }
  1539.         } else if(cb.getText().equals("Paint Focus")) {
  1540.         c = (Component) currentControls.elementAt(0);
  1541.         if(c instanceof AbstractButton) {
  1542.             for(int i = 0; i < currentControls.size(); i++) {
  1543.             b = (AbstractButton) currentControls.elementAt(i);
  1544.             b.setFocusPainted(cb.isSelected());
  1545.                 b.invalidate();
  1546.             }
  1547.         }
  1548.         } else if(cb.getText().equals("Content Filled")) {
  1549.         c = (Component) currentControls.elementAt(0);
  1550.         if(c instanceof AbstractButton) {
  1551.             for(int i = 0; i < currentControls.size(); i++) {
  1552.             b = (AbstractButton) currentControls.elementAt(i);
  1553.             b.setContentAreaFilled(cb.isSelected());
  1554.                 b.invalidate();
  1555.             }
  1556.         }
  1557.         }
  1558.         int index = tabbedPane.getSelectedIndex();
  1559.         Component currentPage = tabbedPane.getComponentAt(index);
  1560.         currentPage.invalidate();
  1561.         currentPage.validate();
  1562.         currentPage.repaint();
  1563.     }
  1564.     };
  1565.  
  1566.     // Text Position
  1567.     ActionListener textPositionListener = new ActionListener() {
  1568.     public void actionPerformed(ActionEvent e) {
  1569.         JRadioButton rb = (JRadioButton) e.getSource();
  1570.         if(rb.isSelected()) {
  1571.         if(rb.getActionCommand().equals("NW")) {
  1572.             for(int i = 0; i < currentControls.size(); i++) {
  1573.             Component c = (Component) currentControls.elementAt(i);
  1574.             if(c instanceof AbstractButton) {
  1575.                 AbstractButton x = (AbstractButton) c;
  1576.                 setNWposition(x);
  1577.             } else if(c instanceof JLabel) {
  1578.                 JLabel x = (JLabel) c;
  1579.                 setNWposition(x);
  1580.             }
  1581.             }
  1582.         } else if(rb.getActionCommand().equals("N")) {
  1583.             for(int i = 0; i < currentControls.size(); i++) {
  1584.             Component c = (Component) currentControls.elementAt(i);
  1585.             if(c instanceof AbstractButton) {
  1586.                 AbstractButton x = (AbstractButton) c;
  1587.                 setNposition(x);
  1588.             } else if(c instanceof JLabel) {
  1589.                 JLabel x = (JLabel) c;
  1590.                 setNposition(x);
  1591.             }
  1592.             }
  1593.         } else if(rb.getActionCommand().equals("NE")) {
  1594.             for(int i = 0; i < currentControls.size(); i++) {
  1595.             Component c = (Component) currentControls.elementAt(i);
  1596.             if(c instanceof AbstractButton) {
  1597.                 AbstractButton x = (AbstractButton) c;
  1598.                 setNEposition(x);
  1599.             } else if(c instanceof JLabel) {
  1600.                 JLabel x = (JLabel) c;
  1601.                 setNEposition(x);
  1602.             }
  1603.             }
  1604.         } else if(rb.getActionCommand().equals("W")) {
  1605.             for(int i = 0; i < currentControls.size(); i++) {
  1606.             Component c = (Component) currentControls.elementAt(i);
  1607.             if(c instanceof AbstractButton) {
  1608.                 AbstractButton x = (AbstractButton) c;
  1609.                 setWposition(x);
  1610.             } else if(c instanceof JLabel) {
  1611.                 JLabel x = (JLabel) c;
  1612.                 setWposition(x);
  1613.             }
  1614.             }
  1615.         } else if(rb.getActionCommand().equals("C")) {
  1616.             for(int i = 0; i < currentControls.size(); i++) {
  1617.             Component c = (Component) currentControls.elementAt(i);
  1618.             if(c instanceof AbstractButton) {
  1619.                 AbstractButton x = (AbstractButton) c;
  1620.                 setCposition(x);
  1621.             } else if(c instanceof JLabel) {
  1622.                 JLabel x = (JLabel) c;
  1623.                 setCposition(x);
  1624.             }
  1625.             }
  1626.         } else if(rb.getActionCommand().equals("E")) {
  1627.             for(int i = 0; i < currentControls.size(); i++) {
  1628.             Component c = (Component) currentControls.elementAt(i);
  1629.             if(c instanceof AbstractButton) {
  1630.                 AbstractButton x = (AbstractButton) c;
  1631.                 setEposition(x);
  1632.             } else if(c instanceof JLabel) {
  1633.                 JLabel x = (JLabel) c;
  1634.                 setEposition(x);
  1635.             }
  1636.             }
  1637.         } else if(rb.getActionCommand().equals("SW")) {
  1638.             for(int i = 0; i < currentControls.size(); i++) {
  1639.             Component c = (Component) currentControls.elementAt(i);
  1640.             if(c instanceof AbstractButton) {
  1641.                 AbstractButton x = (AbstractButton) c;
  1642.                 setSWposition(x);
  1643.             } else if(c instanceof JLabel) {
  1644.                 JLabel x = (JLabel) c;
  1645.                 setSWposition(x);
  1646.             }
  1647.             }
  1648.         } else if(rb.getActionCommand().equals("S")) {
  1649.             for(int i = 0; i < currentControls.size(); i++) {
  1650.             Component c = (Component) currentControls.elementAt(i);
  1651.             if(c instanceof AbstractButton) {
  1652.                 AbstractButton x = (AbstractButton) c;
  1653.                 setSposition(x);
  1654.             } else if(c instanceof JLabel) {
  1655.                 JLabel x = (JLabel) c;
  1656.                 setSposition(x);
  1657.             }
  1658.             }
  1659.         } else if(rb.getActionCommand().equals("SE")) {
  1660.             for(int i = 0; i < currentControls.size(); i++) {
  1661.             Component c = (Component) currentControls.elementAt(i);
  1662.             if(c instanceof AbstractButton) {
  1663.                 AbstractButton x = (AbstractButton) c;
  1664.                 setSEposition(x);
  1665.             } else if(c instanceof JLabel) {
  1666.                 JLabel x = (JLabel) c;
  1667.                 setSEposition(x);
  1668.             }
  1669.             }
  1670.         }
  1671.         int index = tabbedPane.getSelectedIndex();
  1672.                 Component currentPage = tabbedPane.getComponentAt(index);
  1673.         currentPage.invalidate();
  1674.         currentPage.validate();
  1675.         currentPage.repaint();
  1676.         } else {
  1677.         }
  1678.     }
  1679.     };
  1680.  
  1681.  
  1682.     // Label Alignment
  1683.     ActionListener labelAlignmentListener = new ActionListener() {
  1684.     public void actionPerformed(ActionEvent e) {
  1685.         JRadioButton rb = (JRadioButton) e.getSource();
  1686.         if(rb.isSelected()) {
  1687.         if(rb.getActionCommand().equals("NW")) {
  1688.             for(int i = 0; i < currentControls.size(); i++) {
  1689.             Component c = (Component) currentControls.elementAt(i);
  1690.             if(c instanceof AbstractButton) {
  1691.                 AbstractButton x = (AbstractButton) c;
  1692.                 setNWalignment(x);
  1693.                 x.invalidate();
  1694.             } else if(c instanceof JLabel) {
  1695.                 JLabel x = (JLabel) c;
  1696.                 setNWalignment(x);
  1697.                 x.invalidate();
  1698.             }
  1699.             }
  1700.         } else if(rb.getActionCommand().equals("N")) {
  1701.             for(int i = 0; i < currentControls.size(); i++) {
  1702.             Component c = (Component) currentControls.elementAt(i);
  1703.             if(c instanceof AbstractButton) {
  1704.                 AbstractButton x = (AbstractButton) c;
  1705.                 setNalignment(x);
  1706.                 x.invalidate();
  1707.             } else if(c instanceof JLabel) {
  1708.                 JLabel x = (JLabel) c;
  1709.                 setNalignment(x);
  1710.                 x.invalidate();
  1711.             }
  1712.             }
  1713.         } else if(rb.getActionCommand().equals("NE")) {
  1714.             for(int i = 0; i < currentControls.size(); i++) {
  1715.             Component c = (Component) currentControls.elementAt(i);
  1716.             if(c instanceof AbstractButton) {
  1717.                 AbstractButton x = (AbstractButton) c;
  1718.                 setNEalignment(x);
  1719.                 x.invalidate();
  1720.             } else if(c instanceof JLabel) {
  1721.                 JLabel x = (JLabel) c;
  1722.                 setNEalignment(x);
  1723.                 x.invalidate();
  1724.             }
  1725.             }
  1726.         } else if(rb.getActionCommand().equals("W")) {
  1727.             for(int i = 0; i < currentControls.size(); i++) {
  1728.             Component c = (Component) currentControls.elementAt(i);
  1729.             if(c instanceof AbstractButton) {
  1730.                 AbstractButton x = (AbstractButton) c;
  1731.                 setWalignment(x);
  1732.                 x.invalidate();
  1733.             } else if(c instanceof JLabel) {
  1734.                 JLabel x = (JLabel) c;
  1735.                 setWalignment(x);
  1736.                 x.invalidate();
  1737.             }
  1738.             }
  1739.         } else if(rb.getActionCommand().equals("C")) {
  1740.             for(int i = 0; i < currentControls.size(); i++) {
  1741.             Component c = (Component) currentControls.elementAt(i);
  1742.             if(c instanceof AbstractButton) {
  1743.                 AbstractButton x = (AbstractButton) c;
  1744.                 setCalignment(x);
  1745.                 x.invalidate();
  1746.             } else if(c instanceof JLabel) {
  1747.                 JLabel x = (JLabel) c;
  1748.                 setCalignment(x);
  1749.                 x.invalidate();
  1750.             }
  1751.             }
  1752.         } else if(rb.getActionCommand().equals("E")) {
  1753.             for(int i = 0; i < currentControls.size(); i++) {
  1754.             Component c = (Component) currentControls.elementAt(i);
  1755.             if(c instanceof AbstractButton) {
  1756.                 AbstractButton x = (AbstractButton) c;
  1757.                 setEalignment(x);
  1758.                 x.invalidate();
  1759.             } else if(c instanceof JLabel) {
  1760.                 JLabel x = (JLabel) c;
  1761.                 setEalignment(x);
  1762.                 x.invalidate();
  1763.             }
  1764.             }
  1765.         } else if(rb.getActionCommand().equals("SW")) {
  1766.             for(int i = 0; i < currentControls.size(); i++) {
  1767.             Component c = (Component) currentControls.elementAt(i);
  1768.             if(c instanceof AbstractButton) {
  1769.                 AbstractButton x = (AbstractButton) c;
  1770.                 setSWalignment(x);
  1771.                 x.invalidate();
  1772.             } else if(c instanceof JLabel) {
  1773.                 JLabel x = (JLabel) c;
  1774.                 setSWalignment(x);
  1775.                 x.invalidate();
  1776.             }
  1777.             }
  1778.         } else if(rb.getActionCommand().equals("S")) {
  1779.             for(int i = 0; i < currentControls.size(); i++) {
  1780.             Component c = (Component) currentControls.elementAt(i);
  1781.             if(c instanceof AbstractButton) {
  1782.                 AbstractButton x = (AbstractButton) c;
  1783.                 setSalignment(x);
  1784.                 x.invalidate();
  1785.             } else if(c instanceof JLabel) {
  1786.                 JLabel x = (JLabel) c;
  1787.                 setSalignment(x);
  1788.                 x.invalidate();
  1789.             }
  1790.             }
  1791.         } else if(rb.getActionCommand().equals("SE")) {
  1792.             for(int i = 0; i < currentControls.size(); i++) {
  1793.             Component c = (Component) currentControls.elementAt(i);
  1794.             if(c instanceof AbstractButton) {
  1795.                 AbstractButton x = (AbstractButton) c;
  1796.                 setSEalignment(x);
  1797.                 x.invalidate();
  1798.             } else if(c instanceof JLabel) {
  1799.                 JLabel x = (JLabel) c;
  1800.                 setSEalignment(x);
  1801.                 x.invalidate();
  1802.             }
  1803.             }
  1804.         }
  1805.         int index = tabbedPane.getSelectedIndex();
  1806.                 Component currentPage = tabbedPane.getComponentAt(index);
  1807.         currentPage.invalidate();
  1808.         currentPage.validate();
  1809.         currentPage.repaint();
  1810.         }
  1811.     }
  1812.     };
  1813.  
  1814.     // Title Pane tile position
  1815.     ActionListener borderedPaneListener = new ActionListener() {
  1816.     public void actionPerformed(ActionEvent e) {
  1817.         JRadioButton b = (JRadioButton) e.getSource();
  1818.         if(b.getText().equals("Above Top")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.ABOVE_TOP);}
  1819.         if(b.getText().equals("Top")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.TOP);}
  1820.         if(b.getText().equals("Below Top")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.BELOW_TOP);}
  1821.  
  1822.         if(b.getText().equals("Above Bottom")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.ABOVE_BOTTOM);}
  1823.         if(b.getText().equals("Bottom")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.BOTTOM);}
  1824.         if(b.getText().equals("Below Bottom")) {((TitledBorder)borderedPane.getBorder()).setTitlePosition(TitledBorder.BELOW_BOTTOM);}
  1825.  
  1826.         if(b.getText().equals("Left")) {((TitledBorder)borderedPane.getBorder()).setTitleJustification(TitledBorder.LEFT);}
  1827.         if(b.getText().equals("Center")) {((TitledBorder)borderedPane.getBorder()).setTitleJustification(TitledBorder.CENTER);}
  1828.         if(b.getText().equals("Right")) {((TitledBorder)borderedPane.getBorder()).setTitleJustification(TitledBorder.RIGHT);}
  1829.  
  1830.         borderedPane.invalidate();
  1831.         borderedPane.validate();
  1832.         borderedPane.repaint();
  1833.     }
  1834.     };
  1835.  
  1836.     public static JPanel createHorizontalPanel(boolean threeD) {
  1837.     JPanel p = new JPanel();
  1838.     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
  1839.     if(threeD) {
  1840.         p.setBorder(loweredBorder);
  1841.     }
  1842.     return p;
  1843.     }
  1844.  
  1845.     public static JPanel createVerticalPanel(boolean threeD) {
  1846.     JPanel p = new JPanel();
  1847.     p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
  1848.     if(threeD) {
  1849.         p.setBorder(loweredBorder);
  1850.     }    
  1851.     return p;
  1852.     }
  1853.  
  1854.     public static String contentsOfFile(String filename) {
  1855.     String s = new String();
  1856.     File f;
  1857.     char[] buff = new char[50000];
  1858.     InputStream is;
  1859.     InputStreamReader reader;
  1860.     boolean fromApplet = SwingSet.sharedInstance().isApplet();
  1861.     URL url;
  1862.  
  1863.     try {
  1864.       if(fromApplet) {
  1865.         url = new URL(SwingSet.sharedInstance().getApplet().getCodeBase(),filename);
  1866.         is = url.openStream();
  1867.         reader = new InputStreamReader(is);
  1868.       } else {
  1869.         f = new File(filename);
  1870.         reader = new FileReader(f);
  1871.       }
  1872.       int nch;
  1873.       while ((nch = reader.read(buff, 0, buff.length)) != -1) {
  1874.         s = s + new String(buff, 0, nch);
  1875.       }
  1876.     } catch (java.io.IOException ex) {
  1877.         s = "Could not load file: " + filename;
  1878.     }
  1879.  
  1880.     return s;
  1881.     }
  1882.  
  1883.     class ColoredSquare implements Icon {
  1884.     Color color;
  1885.     public ColoredSquare(Color c) {
  1886.         this.color = c;
  1887.     }
  1888.  
  1889.     public void paintIcon(Component c, Graphics g, int x, int y) {
  1890.         Color oldColor = g.getColor();
  1891.         g.setColor(color);
  1892.         g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
  1893.         g.setColor(oldColor);
  1894.     }
  1895.     public int getIconWidth() { return 12; }
  1896.     public int getIconHeight() { return 12; }
  1897.  
  1898.     }
  1899.  
  1900.   public ImageIcon loadImageIcon(String filename, String description) {
  1901.     if(applet == null) {
  1902.       return new ImageIcon(filename, description);
  1903.     } else {
  1904.       URL url;
  1905.       try {
  1906.     url = new URL(applet.getCodeBase(),filename);
  1907.       } catch(MalformedURLException e) {
  1908.       System.err.println("Error trying to load image " + filename);
  1909.       return null;
  1910.       }
  1911.       return new ImageIcon(url, description);
  1912.     }
  1913.   }
  1914.  
  1915.   public static SwingSet sharedInstance() {
  1916.     return instance;
  1917.   }
  1918.  
  1919.   public java.applet.Applet getApplet() {
  1920.     return applet;
  1921.   }
  1922.  
  1923.   public boolean isApplet() {
  1924.     return (applet != null);
  1925.   }
  1926.  
  1927.   public Container getRootComponent() {
  1928.     if(isApplet())
  1929.       return applet;
  1930.     else
  1931.       return frame;
  1932.   }
  1933.  
  1934.   public Frame getFrame() {
  1935.     if(isApplet()) {
  1936.       Container parent;
  1937.       for(parent = getApplet(); parent != null && !(parent instanceof Frame) ; parent = parent.getParent());
  1938.       if(parent != null)
  1939.     return (Frame)parent;
  1940.       else
  1941.     return null;
  1942.     } else
  1943.       return frame;
  1944.   }
  1945.  
  1946.   class FilePreviewer extends JComponent implements PropertyChangeListener {
  1947.       ImageIcon thumbnail = null;
  1948.       File f = null;
  1949.       
  1950.       public FilePreviewer(JFileChooser fc) {
  1951.       setPreferredSize(new Dimension(100, 50));
  1952.       fc.addPropertyChangeListener(this);
  1953.       }
  1954.       
  1955.       public void loadImage() {
  1956.       if(f != null) {
  1957.           ImageIcon tmpIcon = new ImageIcon(f.getPath());
  1958.           if(tmpIcon.getIconWidth() > 90) {
  1959.           thumbnail = new ImageIcon(
  1960.               tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT));
  1961.           } else {
  1962.           thumbnail = tmpIcon;
  1963.           }
  1964.       }
  1965.       }
  1966.       
  1967.       public void propertyChange(PropertyChangeEvent e) {
  1968.       String prop = e.getPropertyName();
  1969.       if(prop == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) {
  1970.           f = (File) e.getNewValue();
  1971.           if(isShowing()) {
  1972.           loadImage();
  1973.           repaint();
  1974.           }
  1975.       }
  1976.       }
  1977.       
  1978.       public void paint(Graphics g) {
  1979.       if(thumbnail == null) {
  1980.           loadImage();
  1981.       }
  1982.       if(thumbnail != null) {
  1983.           int x = getWidth()/2 - thumbnail.getIconWidth()/2;
  1984.           int y = getHeight()/2 - thumbnail.getIconHeight()/2;
  1985.           if(y < 0) {
  1986.           y = 0;
  1987.           }
  1988.           
  1989.           if(x < 5) {
  1990.           x = 5;
  1991.           }
  1992.           thumbnail.paintIcon(this, g, x, y);
  1993.       }
  1994.       }
  1995.   }
  1996. }
  1997.